C++: The Ultimate Beginner's Guide! by Andrew Johansen

C++: The Ultimate Beginner's Guide! by Andrew Johansen

Author:Andrew Johansen [Johansen, Andrew]
Language: eng
Format: epub
Published: 2016-01-11T18:30:00+00:00


This sample code defines two different variables that belong to the same class. You can only use auto inside functions. That means you can only apply this storage class on local variables.

Extern

With this storage class, you can make references to global variables that are accessible to all of your program files. When using this extern, you cannot initialize the variable since it only points the variable name to a memory location you have defined previously.

If you have several files and you have defined a global function or variable, which can also be used in different files, you may use extern on a different file to reference your predefined function or variable.

This modifier is typically used when the programmer has multiple files that share similar global functions or variables.

Mutable

You can only apply this modifier on class objects. The mutable storage class allows an object’s member to override the const function.

Register

You should use this storage class when defining local variables that must be saved inside a register (i.e. not in the machine’s RAM). Thus, the variable’s maximum size is equal to the register’s size (typically a single word). Additionally, these variables cannot possess the “&” operator since they don’t have a specific location in the computer’s memory.

In general, you should use this register to store variables that need fast access (e.g. counters). It is important to note that defining a “register” is different from storing a variable in the register. That means you can store quick-access variables inside a register, based on implementation and hardware limitations.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.